package com.thread;

public class TestThreadName extends Thread {

	@Override
	public void run() {
		revi();
	}
	
	
	TestThreadName(){
		
	}
	
	TestThreadName(String name){
		//给线程起一个名字
		super(name);
	}
	
	
	public void revi(){
		if("thread-111".equals(Thread.currentThread().getName())){
			//System.out.print(Thread.currentThread().getName());
		}else{
			//System.out.print(Thread.currentThread().getName());
		}
		
	}
	
	public static void main(String[] args) throws InterruptedException{
		
		new TestThreadName("thread-1121").start();
		sleep(2000);
		//返回程序中线程个数
		int i = Thread.activeCount();
		System.out.println(i);
		Thread t[] = new Thread[i];
		//获取程序中线程对象
		int n = Thread.enumerate(t);
		//System.out.println(n);
		for(int c = 0; c<n;c++){
			System.out.println(t[c].isAlive());
			System.out.println(t[c].getName());
		}
	}
	
}
